<template>
	<div>
		<el-form :model="addData" ref='child' :rules='rules'>
			<el-row :gutter="20">
  			<el-col :span="8" :offset="8">
  				<el-form-item label="职位名称" prop='name'>
  					<el-input v-model="addData.name" ></el-input>
  				</el-form-item>
  				<el-form-item label="备注:" prop='remark'>
				<el-input :maxlength='80' type="textarea" :rows="2" placeholder="请输入备注信息" v-model="addData.remark"></el-input>
				</el-form-item>
				<el-form-item label="部门:" prop="store_name" >
				<el-select v-model="addData.store_name" placeholder="选择部门">
				<el-option v-for='(item,index) in storeSelect' :label="item" :value="item" :key='index'></el-option>
				</el-select>
				</el-form-item>
				<el-form-item>
				<el-button type="primary" @click="submitForm('child')">确认添加</el-button>
				<el-button @click="resetForm('child')">重置</el-button>
				</el-form-item>
  			</el-col>
			</el-row>
		</el-form>
	</div>
</template>
<script>
	import {mapGetters,mapActions,mapState} from 'vuex'
	export default{
		name:'addzw',
		data(){
			return{
				addData:{

				},
				rules:{
					name:[
						{ required: true, message: '姓名不能为空!', trigger: 'blur' },
					],
					remark:[
						{ required: true, message: '姓名不能为空!', trigger: 'blur' },
					],
					store_name:[
						{ required: true, message: '姓名不能为空!', trigger: 'blur' },
					],

				}
			}
		},
		computed:{
			...mapGetters(['storeSelect']),
		},
		methods:{
			...mapActions(['addJob']),
			submitForm(formName) {
        		this.$refs[formName].validate((valid) => {
          			if (valid) {
          				//发起请求 判断 数据库更新是否成功
          				this.addData.create_by =parseInt(sessionStorage.getItem('id')) 
							let obj = {
							"create_by": "1004",
							"name": "洗碗工",
							"remark": "洗碗的",
							"store_name": "清洁布"
							}
          				this.addJob(obj)
          				// this.$emit('text',this.editFrom)
          			} else {
            			console.log('error submit!!');
            			return false;
          			}
        		});
      		},
      		resetForm(formName) {
      			this.addData = {}
        		this.$refs[formName].resetFields();
      		}
		}
	}
</script>